/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lectorArchivos;

/**
 *
 * @author gabula
 */
public class Problema {

    private int numNodos;
    private double[][] distancias;
    private double maxDist;

    public Problema(String nombre) {
        LectorDeProblemas lp = new LectorDeProblemas(nombre);
        maxDist = 0;
        numNodos = lp.getNumNodos();
        distancias = obtenerDistancias(lp.getCoord());
    }

    public double[][] obtenerDistancias(int[][] coord) {
        double[][] dist = new double[getNumNodos()][getNumNodos()];
        for (int i = 0; i < getNumNodos(); ++i) {
            for (int j = 0; j < getNumNodos(); ++j) {
                if (i == j) {
                    dist[i][j] = 0;
                } else {
                    dist[i][j] = Math.round(Math.sqrt(((coord[i][0] - coord[j][0]) * (coord[i][0] - coord[j][0]) + (coord[i][1] - coord[j][1]) * (coord[i][1] - coord[j][1]))));
                    maxDist +=dist[i][j];
                }
            }
        }
        return dist;
    }

    public void imprimir() {
        java.text.DecimalFormat df = new java.text.DecimalFormat("##.00");
        java.text.DecimalFormatSymbols dfs = new java.text.DecimalFormatSymbols();
        dfs.setDecimalSeparator('.');
        df.setDecimalFormatSymbols(dfs);
        System.out.println("Numero de nodos: " + getNumNodos());
        for (int i = 0; i < getNumNodos(); ++i) {
            for (int j = 0; j < getNumNodos(); ++j) {
                System.out.print(df.format(getDistancias()[i][j]) + " ");
            }
            System.out.print("\n");
        }
    }

    public int getNumNodos() {
        return numNodos;
    }

    public double[][] getDistancias() {
        return distancias;
    }

    public double getMaxDist() {
        return maxDist;
    }
}
